package com.liu.cloud.feign.factory;

import com.liu.cloud.feign.RemoteStockFeignService;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 *
 * 在配置文件application.yml中开启feign熔断器支持
 * 编写FallBack处理类，实现FeignClient客户端
 * 在@FeignClient注解中，指定FallBack处理类。
 *
 * @author LIU
 * @version 1.0
 * @description: TODO
 * @date 2023/7/29 11:04
 */
@Component
@Slf4j
public class RemoteStockFeignFallbackFactory implements FallbackFactory<RemoteStockFeignService> {

    @Override
    public RemoteStockFeignService create(Throwable throwable) {
        log.error("库存服务调用失败了",throwable);
        return new RemoteStockFeignService() {
            @Override
            public String add() {
                return "服务调用失败，降级了";
            }
        };
    }
}
